<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<jsp:directive.page import="com.sky.common.encrypt.Encryptor"/>
<%
	String action=request.getParameter("action");
	String password=request.getParameter("password")==null?"Sky":request.getParameter("password");
	String originaltext=request.getParameter("originaltext")==null?"":request.getParameter("originaltext");
	String ciphertext=request.getParameter("ciphertext")==null?"":request.getParameter("ciphertext");
	//out.println("action:["+action+"]\tpassword:["+password+"]\toriginaltext:["+originaltext+"]\tciphertext:["+ciphertext+"]");
	String error=null;
	if("encrypt".equalsIgnoreCase(action)){
		try{
			ciphertext=Encryptor.encryptText(password,originaltext);
		}catch(Exception e){
			error=e.getMessage();
		}
	}
	if("decrypt".equalsIgnoreCase(action)){
		try{
			originaltext=Encryptor.decryptText(password,ciphertext);
		}catch(Exception e){
			error=e.getMessage();
		}		
	}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>在线文本加解密工具</title>
		<%@include file="/share/header.jsp"%>		
		<style>
			*{
				font-size: 12px;
			}
		</style>
	</head>
	<body>
		<form  name="myform" method="POST" action="Encryptor.jsp">
			<input type="hidden" name="action" value="">
			<table align="center">
				<tr>
					<td colspan="100"  align="center"><hr><font style="font-weight: bold;font-size: 20px;color: green;">在线文本加解密工具</font><hr></td>
				</tr>
				<%if(error!=null){ %>
				<tr>
					<td colspan="100"  align="center"><font style="color: red;"><%=error%></font><hr></td>
				</tr>	
				<%} %>			
				<tr>
					<td><center><b>明文：</b></center><textarea cols="60" rows="30" name="originaltext"><%=originaltext%></textarea></td>
					<td  align="center">
						<b>密钥：</b><input type="text" name="password" value="<%=password%>" size="6"  autocomplete="off">
						<br>
						<br>
						<br>
						<br>
						<br>
						<br>
						<br>
						<br>
						<br>	
						<br>
						<br>
						<br>
						<input type="submit" value="加密(e)-->>" accesskey="e" style="background-color: olive;" onclick="document.myform.action.value='encrypt';">
						<br>
						<input type="submit" value="<<--解密(d)" accesskey="d" style="background-color: slategray;" onclick="document.myform.action.value='decrypt';">
						<br>
						<input type="button" value=" 清  空(c) " accesskey="c" style="background-color: lavender;"  onclick="document.myform.originaltext.value='';document.myform.ciphertext.value='';">						
						<br>
						<br>
						<br>
						<br>	
						<br>
						<br>
						<br>
						<br>
						<br>
						<br>
						<br>
						<br>						
						<br>											
					</td>
					<td><center><b>密文：</b></center><textarea cols="60" rows="30" name="ciphertext"><%=ciphertext%></textarea></td>
				</tr>
				<tr>
					<td colspan="100"  align="center"><hr></td>
				</tr>				
			</table>
		</form>

	</body>
</html>
